package com.ym.controller.medical;

import com.github.pagehelper.PageInfo;
import com.ym.common.annotations.CustomConstraint;
import com.ym.common.utils.page.PageDomain;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;
import com.ym.core.shiro.ShiroUtil;
import com.ym.medical.domain.param.DoctorStudioQueryParam;
import com.ym.medical.domain.param.OpenStudioAppQueryParam;
import com.ym.medical.domain.param.StudioPersonnelUpdateParam;
import com.ym.medical.domain.vo.DoctorLinkVo;
import com.ym.medical.domain.vo.DoctorStudioVo;
import com.ym.medical.domain.vo.OpenStudioAppVo;
import com.ym.medical.enums.StudioAppStatusEnum;
import com.ym.medical.service.IDoctorStudioSV;
import com.ym.medical.service.IOpenStudioAppSV;
import com.ym.medical.service.IOpenStudioReviewSV;
import com.ym.medical.service.IStudioPersonnelSV;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 工作室相关接口
 *
 * @author: 李涛
 * @version: 2019年06月12日 15:51
 */
@Api(tags = "工作室相关接口")
@RestController
@RequestMapping("/management/studio")
@Validated
public class StudioController extends BaseController {


	@Autowired
	private IOpenStudioAppSV openStudioAppSV;

	@Autowired
	private IDoctorStudioSV iDoctorStudioSV;

	@Autowired
	private IOpenStudioReviewSV iopenStudioReviewSV;

	@Autowired
	private IStudioPersonnelSV iStudioPersonnelSV;

	@ApiOperation("工作室申请列表")
	@GetMapping(value = "/applicationReview/list")
	public APIResponse<PageInfo<OpenStudioAppVo>> applicationReviewList(
			OpenStudioAppQueryParam queryParam
	) {
		PageDomain.startPage();
		List<OpenStudioAppVo> openStudioAppPageInfo = openStudioAppSV.applicationReviewList(queryParam);
		return successPage(openStudioAppPageInfo);
	}

	@ApiOperation("工作室申请审核")
	@ApiImplicitParams({
			@ApiImplicitParam(value = "审核的ID", name = "ids", paramType = "form"),
			@ApiImplicitParam(value = "审核状态,KEY=StudioAppStatusEnum", name = "state", paramType = "form"),
			@ApiImplicitParam(value = "意见", name = "remark", paramType = "form"),
	})
	@PostMapping(value = "/applicationReview/audit", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
	public APIResponse applicationReviewAudit(
			Long[] ids,
			@CustomConstraint(value = StudioAppStatusEnum.class) String state,
			String remark
	) {
		openStudioAppSV.applicationReviewAudit(ids, ShiroUtil.getLoginId(true), state, remark);
		return success();
	}

	@ApiOperation("全科工作室列表")
	@GetMapping("/generalStudio")
	@ResponseBody
	public APIResponse<PageInfo<DoctorStudioVo>> generalStudioList(
			@ApiParam(name = "doctorStudioModel", value = "医生工作室信息")
					DoctorStudioQueryParam queryParam) {
		PageDomain.startPage();
		List<DoctorStudioVo> doctorStudios = iDoctorStudioSV.generalStudioList(queryParam);
		return successPage(doctorStudios);

	}

	@ApiOperation("全科工作添加成员")
	@GetMapping("/addStudioPerson")
	@ResponseBody
	public APIResponse addStudioPerson(
			@ApiParam(name = "studioPersonnelModel", value = "医生信息", required = true)
					StudioPersonnelUpdateParam updateParam) {
		int rows = iStudioPersonnelSV.addStudioPerson(updateParam);
		if (rows != 1) {
			return successMsg("操作失败");
		}
		return successMsg("操作成功");
	}

	@ApiOperation("全科专科工作室成员列表")
	@GetMapping("/studioPersonList")
	@ResponseBody
	public APIResponse<PageInfo<DoctorLinkVo>> studioPersonList(
			@ApiParam(name = "pageNo", value = "页码", required = true)
			@RequestParam(name = "pageNo", required = true, defaultValue = "1")
					int pageNo,
			@ApiParam(name = "limit", value = "每页数量", required = false)
			@RequestParam(name = "limit", required = false, defaultValue = "10")
					int limit,
			@RequestParam(name = "doctId", required = true)
					long doctId,
			@RequestParam(name = "doctId", required = true)
					String doctCategory) {
		PageInfo<DoctorLinkVo> doctorLinkVoPageInfo = iStudioPersonnelSV
				.studioPersonList(pageNo, limit, doctId, doctCategory);
		return successData(doctorLinkVoPageInfo);
	}

	@ApiOperation("专科医生友医工作室列表")
	@GetMapping("/specialistFriendDoctor")
	@ResponseBody
	public APIResponse<PageInfo<DoctorStudioVo>> specialistFriendDoctor(
			@ApiParam(name = "pageNo", value = "页码", required = true)
			@RequestParam(name = "pageNo", required = true, defaultValue = "1")
					int pageNo,
			@ApiParam(name = "limit", value = "每页数量", required = false)
			@RequestParam(name = "limit", required = false, defaultValue = "10")
					int limit,
			@RequestParam(name = "doctId", required = true)
					long doctId) {
		PageInfo<DoctorStudioVo> studioVoPageInfo = iDoctorStudioSV.specialistFriendDoctor(pageNo, limit, doctId);
		return successData(studioVoPageInfo);

	}

}
